package com.java46.admin.dessert.filter;

import com.java46.front.dessertType.entity.DesserttypeEntity;
import com.java46.front.dessertType.service.DessertTypeService;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebFilter("/detail/saveFood.jsp")
public class dessertTypeFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //强转请求和相应对象
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //创建商品类型业务对象
        DessertTypeService dessertTypeService = new DessertTypeService();
        List<DesserttypeEntity> desserttypeEntityList = dessertTypeService.getAllDessertType();
        //创建Session对象
        HttpSession session = request.getSession();
        //存放商品类型数据
        session.setAttribute("list",desserttypeEntityList);
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
